package com.heima.kafkas.controller;

import com.alibaba.fastjson.JSON;
import com.heima.kafkas.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class hellowcontroller {
    @Resource
    private KafkaTemplate<String,String> kafkaTemplate;
    @GetMapping("/hellow")
    public String hellow(){
        log.info("收到请求");
        kafkaTemplate.send("kafka-topic","hellow world");
        return "hello world";
    }


    @GetMapping("/student")
    public String student(){
        User user=new User();
        user.setName("小王");
        user.setAge(18);
        kafkaTemplate.send("user-topic", JSON.toJSONString(user));
        return "success";
    }
}
